package com.supertimetable.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.supertimetable.bean.Teacher;
import com.supertimetable.constant.Constant;
import com.supertimetable.tools.HTMLUtils;

import java.util.ArrayList;


/**
 * Created by ooyhao on 2018/1/10.
 */

public class MyDBHelper extends SQLiteOpenHelper {
    private Context c;
    public MyDBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    public MyDBHelper(Context context){
        super(context, Constant.DATABASE_NAME,null,Constant.DATABASE_VERSION);
        c = context;
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        //创建教师表
        String sql1 = "create table " + Constant.TEACHER_TABLE + " (tId text primary key ,tName text,tSex text,tDep text,tProf text)";
        String sql2 = "create table " + Constant.TEACHERTABLE_TABLE + " (tId text,weekTime " +
                "integer,dayTime integer," +
                "courseContent text ,primary key (tId,weekTime,dayTime))";
        db.execSQL(sql1);
        db.execSQL(sql2);

        new Thread(){
            @Override
            public void run() {
                final ArrayList<Teacher> teachers = HTMLUtils.getTeachers();
                DBTeacherUtil.insertTeacher(c,teachers);
            }
        }.start();
    }



    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
